﻿<%@ Page Language="C#" MasterPageFile="../main.master" Inherits="VioletDevelopmentLaboratory.Net.Web.Configuration.VWebConfigManagerPage" %>

<script runat="server">
	protected void AppSettingsGridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
	{
		AppSettingsDetailsView.ChangeMode(DetailsViewMode.ReadOnly);
	}
	protected void AppSettingsDetailsView_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
	{
		ShowAlert_DetailsView_ItemInserted(e);

		AppSettingsGridView.SelectedIndex = -1;
		AppSettingsGridView.DataBind();
	}
	protected void AppSettingsDetailsView_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
	{
		ShowAlert_DetailsView_ItemUpdated(e);

		AppSettingsGridView.SelectedIndex = -1;
		AppSettingsGridView.DataBind();
	}
	protected void AppSettingsDetailsView_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)
	{
		ShowAlert_DetailsView_ItemDeleted(e);

		AppSettingsDetailsView.ChangeMode(DetailsViewMode.Insert);

		AppSettingsGridView.SelectedIndex = -1;
		AppSettingsGridView.DataBind();
	}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPlaceHolder" runat="server">

	<h2>AppSettings</h2>

	<div>
		<asp:ObjectDataSource ID="AppSettingsDetailsViewDataSource" runat="server" InsertMethod="Add" 
			SelectMethod="GetKeyValueConfigurationElement" 
			TypeName="VioletDevelopmentLaboratory.Net.Web.Configuration.AppSettingsSectionManager" 
			UpdateMethod="Modify" DeleteMethod="Remove">
			<DeleteParameters>
				<asp:Parameter Name="key" Type="String" />
			</DeleteParameters>
			<UpdateParameters>
				<asp:Parameter Name="key" Type="String" />
				<asp:Parameter Name="value" Type="String" />
			</UpdateParameters>
			<SelectParameters>
				<asp:ControlParameter ControlID="AppSettingsGridView" Name="key" 
					PropertyName="SelectedValue" Type="String" />
			</SelectParameters>
			<InsertParameters>
				<asp:Parameter Name="key" Type="String" />
				<asp:Parameter Name="value" Type="String" />
			</InsertParameters>
		</asp:ObjectDataSource>
		<asp:ObjectDataSource ID="AppSettingsGridViewDataSource" runat="server" 
			SelectMethod="GetKeyValueConfigurationCollection" 
			TypeName="VioletDevelopmentLaboratory.Net.Web.Configuration.AppSettingsSectionManager">
		</asp:ObjectDataSource>
		<fieldset>
			<asp:DetailsView ID="AppSettingsDetailsView" runat="server" 
				AutoGenerateRows="False" CellPadding="5" DataKeyNames="Key" 
				DataSourceID="AppSettingsDetailsViewDataSource" DefaultMode="Insert" oniteminserted="AppSettingsDetailsView_ItemInserted" 
				onitemupdated="AppSettingsDetailsView_ItemUpdated" 
				onitemdeleted="AppSettingsDetailsView_ItemDeleted">
				<Fields>
					<asp:BoundField DataField="Key" HeaderText="Key" ReadOnly="True" 
						SortExpression="Key" />
					<asp:BoundField DataField="Value" HeaderText="Value" SortExpression="Value" />
					<asp:CommandField ButtonType="Button" ShowDeleteButton="True" 
						ShowEditButton="True" ShowInsertButton="True" />
				</Fields>
			</asp:DetailsView>
			<asp:GridView ID="AppSettingsGridView" runat="server" CellPadding="5" 
				AutoGenerateColumns="False" DataSourceID="AppSettingsGridViewDataSource" DataKeyNames="Key" 
				onselectedindexchanging="AppSettingsGridView_SelectedIndexChanging">
				<Columns>
					<asp:CommandField ShowSelectButton="true" />
					<asp:BoundField DataField="Key" HeaderText="Key" ReadOnly="True" />
					<asp:BoundField DataField="Value" HeaderText="Value" />
				</Columns>
				<SelectedRowStyle BackColor="SkyBlue" />
			</asp:GridView>
		</fieldset>
	</div>
</asp:Content>